
const {request} = require('./request')

//获取首页信息
export function getHomeInfo() {
  return request({
    url: '/home/index'
  })
}

//获取商品详细信息
export function getGoodsDetail(data) {
  return request({
    url: '/goods/detail',
    params: {
      id: data.id
    }
  })
}

//获取一级分类信息
export function getCategory() {
  return request({
    url: '/catalog/index',
   
  })
}

//获取二级分类信息
export function getSecCategory(data) {
  return request({
    url: '/catalog/current',
    params: {
      id: data.id
    }
  })
}

//搜索
export function searchGoods(data) {
  const info = {
    url: '/goods/list',
    params: {
      categoryId: data.categoryId,
    }
  }
  if(data.keyword) {
    info.params.keyword = data.keyword
  }else if(data.categoryId) {
    info.params.categoryId = data.categoryId
  }
  return request(info)
}

//账号注册
export function startRegister(config) {
  return request({
    url: '/auth/register',
    data: {
      username: config.username,
      password:config.password,
      mobile:config.mobile,
      code:config.code
    },
    method: 'post'
  })
}
//账号登录
export function Login(config) {
  return request({
    url: '/auth/login',
    data: {
      username: config.username,
      password:config.password
    },
    method: 'post'
  })
}
//账号退出
export function logout() {
  return request({
    url: '/auth/logout',
    method: 'post'
  })
}
//用户信息重置
export function updateInfo(config) {
  return request({
    url: '/auth/updateInfo',
    data: {
      filePath: config.filePath,
      nickname: config.nickname,
      mobile: config.mobile,
      password: config.password,
    },
    method: 'post'
  })
}
//账号重置
export function updateId(config) {
  return request({
    url: '/auth/reset',
    data: {
      code: '123',
      mobile: config.mobile,
      password: config.password,
    },
    method: 'post'
  })
}
//添加或删除收藏
export function addOrDelCollect(data) {
  return request({
    url: '/collect/addordelete',
    data: {
      type: data.type,
      valueId: data.id
    },
    method: 'post'
  })
}
//加入购物车商品
export function addShoppingCart(data) {
  return request({
    url: '/cart/add',
    data: {
      goodsId: data.goodsId,
      number: data.number,
      productId: data.productId
    },
    method: 'post'
  })
}
//删除购物车商品
export function delShoppingCart(data) {
  return request({
    url: '/cart/delete',
    data: {
      productIds: data.productIds
    },
    method: 'post'
  })
}
//查询购物车商品
export function getShoppingCart() {
  return request({
    url: '/cart/index',
  })
}
//更新购物车商品
export function updateShoppingCart(config) {
  return request({
    url: '/cart/update',
    data: {
      productId: config.productId,
      goodsId: config.goodsId,
      number: config.number,
      id: config.id
    },
    method: 'post'
  })
}

//查询收藏
export function getCollect(data) {
  return request({
    url: '/collect/list',
    params: {
      type: data.type,
      page: data.page
    },
  })
}

//添加收货地址
export function addAddress(config) {
  return request({
    url: '/address/save',
    data: {
      name: config.name,
      tel: config.tel,
      province:config.province,
      city:config.city,
      county:config.county,
      addressDetail:config.addressDetail,
      isDefault:config.isDefault,
    },
    method: 'post'
  })
}
//查询收货地址列表
export function getAddress() {
  return request({
    url: '/address/list',
  })
}
//查询收货地址详情
export function getAddressDetail(config) {
  return request({
    url: '/address/detail',
    params: {
      id: config.id
    }
  })
}
//删除收货地址
export function delAddress(config) {
  return request({
    url: '/address/delete',
    data: {
      id: config.id
    },
    method: 'post'
  })
}
//下单前信息确认
export function cartCheckout(config) {
  return request({
    url: '/cart/checkout',
    data: {
      id: config.id
    },
  })
}

//购买商品缓存购买信息
export function cacheInfo(config) {
  return request({
    url: '/cart/fastadd',
    data: {
      goodsId: config.goodsId,
      number: config.number,
      productId: config.productId,
    },
    method: 'post'
  })
}
//提交订单
export function orderSubmit(config) {
  return request({
    url: '/order/submit',
    data: {
      cartId: config.cartId,
      addressId: config.addressId,
      couponId: 0,
      userCouponId: 0,
      message: config.message,
      grouponRulesId: 0,
      grouponLinkId: 0,
      
    },
    method: 'post'
  })
}
//取消订单
export function closeOrder(config) {
  return request({
    url: '/order/cancel',
    data: {
      orderId: config.orderId,
    },
    method: 'post'
  })
}
//选择或取消选择商品
export function toggleChooseGoods(config) {
  return request({
    url: '/cart/checked',
    data: {
      productIds: config.productIds,
      isChecked: config.isChecked
    },
    method: 'post'
  })
}
//订单退款
export function refund(config) {
  return request({
    url: '/order/refund',
    data: {
      orderId: config.orderId,
    },
    method: 'post'
  })
}
//订单列表
export function orderList(config) {
  return request({
    url: '/order/list',
    params: {
      showType: config.showType,
      limit: 99
    },
    
  })
}
//立即支付
export function orderPay(config) {
  return request({
    url: '/order/pay',
    data: {
      orderId: config.orderId,
    },
    method: 'post'
  })
}
//确认收货
export function confirmGoods(config) {
  return request({
    url: '/order/confirm',
    data: {
      orderId: config.orderId,
    },
    method: 'post'
  })
}
//浏览历史记录
export function getHistoryList() {
  return request({
    url: '/footprint/list',
   
  })
}
//删除足迹记录
export function delHistoryItem(config) {
  return request({
    url: '/footprint/delete',
    data: {
      id: config.id
    },
    method: 'post'
  })
}
//获取品牌列表
export function getBrandList(config) {
  return request({
    url: '/brand/list',
    params: {
      limit: 50
    }
  })
}
//获取品牌详情
export function getBrandDetail(config) {
  return request({
    url: '/brand/detail',
    params: {
      id: config.id
    }
  })
}

//获取用户信息
export function getUserInfo() {
  return request({
    url: '/auth/info',
    
  })
}
//立即评价
export function atOnceEvaluation(config) {
  return request({
    url: '/comment/post',
    data: {
      orderGoodsId: config.orderGoodsId,
      content: config.content,
      star: config.star,
      hasPicture: config.hasPicture,
      filePath: config.filePath
    },
    method: 'post'
  })
}